package com.api

/**
 * trait的demo
 */
trait IsEqual{
  def isEqual(param:Any):Boolean
  def isNotEqual(param:Any):Boolean={
   !isEqual(param)
  }

}
class Point extends IsEqual{
  var x=0;
  var y=0;
  def this(ox:Int,oy:Int){
    this    //首先调用Point的无参构造
    this.x=ox;
    this.y=oy;
  }
  override def isEqual(param: Any): Boolean = {
    param.isInstanceOf[Point]&&
      param.asInstanceOf[Point].x.equals(this.x)&&
      param.asInstanceOf[Point].y.equals(this.y)
  }
}


object Trait {
  def main(args: Array[String]): Unit = {
    val p1=new Point(1,1)
    val p2=new Point(1,2)
    println(p1.isEqual(p2))
    println(p1.isNotEqual(p2))
  }
}
